<?php
require_once "HTMLable.php";

class FormTempl extends HTMLable {
	protected $type, $values;
	
	public function __construct($type, $values = null) {
		$this->type = $type;
		$this->values = $values;
	}
	
	public function genHTML() {
		if      ($this->type == "article")
			$this->html = $this->articleForm();
		else if ($this->type == "user")
			$this->html = $this->userForm();
	}
	
	private function articleForm() {
		$act = "write";
		if ($this->values !== null)
			$act = "edit&id=".$this->values->aid;
		
		return "
<div class=\"writearticle\">
	<p>All fields are required, including the image.</p>
	<form method=\"post\" enctype=\"multipart/form-data\" action=\"proc/proc_article.php?act=".$act."\">
		<p><input type=\"text\" name=\"subject\" value=\"".$this->values->subject."\" /> Subject</p>
		<p><textarea name=\"text\">".$this->values->text."</textarea></p>
		<p><input type=\"file\" name=\"img\" /> Image</p>
		<p><input type=\"submit\" value=\"Send blog post\" /></p>
	</form>
</div>";
	}
	
	private function userForm() {
		return "
		<div class=\"user public\">
			<h3>".$this->name."</h3>
			<form action=\"proc/proc_edituserinfo.php\" method=\"post\">
				<p><input type=\"text\" name=\"given\" value=\"".$this->values->given."\"/> Given name</p>
				<p><input type=\"text\" name=\"surname\" value=\"".$this->values->surname."\" /> Surname</p>
				<p><input type=\"password\" name=\"pass1\" /> Password</p>
				<p><input type=\"password\" name=\"pass2\" /> Repeat password</p>
				<p><input type=\"text\" name=\"nationality\" value=\"".$this->values->nationality."\" /> Nationality</p>
				<p><input type=\"text\" name=\"date_of_birth\" value=\"".$this->values->date_of_birth."\" /> Date of birth</p>
				<p><input type=\"submit\" value=\"Edit info\" /></p>
			</form>
		</div>";
	}
}
?>
